﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.BarterSystem.Barterables.MercenaryJoinKingdomBarterable
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.BarterSystem.Barterables
{
  public class MercenaryJoinKingdomBarterable : Barterable
  {
    [SaveableField(700)]
    private readonly Kingdom _targetKingdom;

    public override string StringID => "mercenary_join_faction_barterable";

    public MercenaryJoinKingdomBarterable(Hero owner, PartyBase ownerParty, Kingdom targetKingdom)
      : base(owner, ownerParty)
    {
      this._targetKingdom = targetKingdom;
    }

    public override TextObject Name
    {
      get
      {
        TextObject name = new TextObject("{=PaG0Blui}Become a mercenary for {TARGET_FACTION}");
        name.SetTextVariable("TARGET_FACTION", this._targetKingdom.Name);
        return name;
      }
    }

    public override int GetUnitValueForFaction(IFaction faction)
    {
      float unitValueForFaction = 0.0f;
      if (this._targetKingdom == faction.MapFaction)
        unitValueForFaction += Campaign.Current.Models.DiplomacyModel.GetScoreOfKingdomToHireMercenary(this._targetKingdom, this.OriginalOwner.Clan);
      else if (faction == this.OriginalOwner.Clan)
      {
        if (this.OriginalOwner.Clan.Kingdom != null)
          unitValueForFaction += Campaign.Current.Models.DiplomacyModel.GetScoreOfMercenaryToLeaveKingdom(this.OriginalOwner.Clan, this.OriginalOwner.Clan.Kingdom);
        unitValueForFaction += Campaign.Current.Models.DiplomacyModel.GetScoreOfMercenaryToJoinKingdom(this.OriginalOwner.Clan, this._targetKingdom);
      }
      return (int) unitValueForFaction;
    }

    public override void CheckBarterLink(Barterable linkedBarterable)
    {
    }

    public override ImageIdentifier GetVisualIdentifier() => (ImageIdentifier) null;

    public override string GetEncyclopediaLink() => this._targetKingdom.EncyclopediaLink;

    public override void Apply()
    {
      ChangeKingdomAction.ApplyByJoinFactionAsMercenary(this.OriginalOwner.Clan, this._targetKingdom, Campaign.Current.Models.MinorFactionsModel.GetMercenaryAwardFactorToJoinKingdom(this.OriginalOwner.Clan, this._targetKingdom));
    }

    internal static void AutoGeneratedStaticCollectObjectsMercenaryJoinKingdomBarterable(
      object o,
      List<object> collectedObjects)
    {
      ((Barterable) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._targetKingdom);
    }

    internal static object AutoGeneratedGetMemberValue_targetKingdom(object o)
    {
      return (object) ((MercenaryJoinKingdomBarterable) o)._targetKingdom;
    }
  }
}
